package com.xiaotu.mapper;

import com.xiaotu.model.PlayerModel;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * @author zhangxiao
 * @create 2021-10-15 13:57
 */
@org.apache.ibatis.annotations.Mapper
public interface PlayerMapper extends Mapper<PlayerModel> {

    @Select(" SELECT * FROM tab_player WHERE battle_status = 1 AND player_id != #{playerId} limit 1 ")
    PlayerModel getPreparingPlayer(@Param("playerId") Integer playerId);

    @Update("<script>" +
            " <foreach collection='list' item='v' separator=';'>" +
            " UPDATE `tab_player` SET `battle_status` = #{battleStatus} WHERE `player_id` = #{v} " +
            "</foreach> " +
            "</script>")
    void batchUpdateBattleStatus(@Param("list") List<Integer> playerIds, @Param("battleStatus") Integer battleStatus);
}
